
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test_project/event_bus_utils/EventBus.dart';
import 'package:flutter_test_project/module/bus_test_page/components/bus_config.dart';
import 'package:flutter_test_project/module/bus_test_page/components/bus_test_sub_widget.dart';

class BusTestPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _BusTestPageState();

}

class _BusTestPageState extends State<BusTestPage> {
  LoginState _loginState = LoginState.logout;
  @override
  void initState() {
    super.initState();
    bus.on("login_state", (arg) {
      final loginState = arg as LoginState;
      print(loginState == LoginState.login ? "登录" : "退出登录");
      setState(() {
        _loginState = arg as LoginState;
      });
    });
  }

  @override
  void dispose() {
    super.dispose();
    bus.off("login_state");
  }

  @override
  Widget build(BuildContext context) {
    final kScreenWidth = MediaQuery.of(context).size.width;
    final kScreenHeight = MediaQuery.of(context).size.height;
    return Scaffold(
      appBar: AppBar(
        title: Text(
          LoginState.logout == _loginState ? "未登录" : "已登录",
          style: TextStyle(
            color: Colors.black12,
            fontSize: 18,
            fontWeight: FontWeight.w600,
          ),
        ),
      ),
      body:  Container(
        width: kScreenWidth,
        height: kScreenHeight,
        color: Colors.grey,
        child: BusTestSubWidget(),
      ),
    );
  }

}